//
//  footerView.m
//  Dental_Fun
//
//  Created by macbook pro on 15/10/8.
//  Copyright (c) 2015年 YZK. All rights reserved.
//

#import "footerView.h"
static NSString *  titleString = @"共一件商品";
#define SET_FONT(s) [UIFont systemFontOfSize:s]
@interface footerView()

@property (nonatomic , weak)UIButton * selectButton;

@end
@implementation footerView

-(instancetype)initWithFrame:(CGRect)frame WithStyle:(Style_maijia)style
{
    
    
    
    if (self = [super initWithFrame:frame]) {
    
//        self.backgroundColor = ComColor;

        
//        self.backgroundColor = UIColorRGB(0xffffff);
        
        [self addSubview:self.titleLabel];
        
        [self addSubview:self.pickLabel];
        
        [self addSubview:self.backLabel];
    
        [self addSubview:self.backView];
        
        self. style = style;

    }
    
    return self;


}
- (void)setYesOrno:(BOOL)yesOrno
{
    
    _yesOrno = yesOrno;
    _backView.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), 40);
    
//    self.titleLabel.textColor = UIColorRGB(0xffffff);
    self.titleLabel.frame = CGRectMake(0, 0, 0, 0);
//    NSLog(@"%@",self.titleLabel);
    titleString = yesOrno ? @"共一键商品":@"";
    
    _titleLabel.hidden = YES;
    _pickLabel.hidden = YES;
    _backLabel.hidden = YES;
    


}

- (UIView *)backView
{
    if (_backView) {
        
        return _backView;
    }
    
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(-1 , CGRectGetMaxY(_backLabel.frame), CGRectGetWidth(self.frame)+ 2, 50)];
    
//  /  view.layer.borderColor = [UIColorRGB(0x333333)CGColor];
//
    
//    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(-1, 39, CGRectGetWidth(view.frame)+2, 11)];
    
//    label.backgroundColor = UIColorRGB(0xf8f8f8);
//    label.layer.borderWidth = .7f;
    
//    label.layer.borderColor = [UIColorRGB(0xd8d8d8)CGColor];
    
//    [view addSubview:label];
    


    _backView = view;

    return _backView;
    
}

- (UILabel *)titleLabel
{
    if (_titleLabel) {
        
        return _titleLabel;
        
        
    }
    
    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, 40)];
//    label.textColor = UIColorRGB(0x666666);
    
//    label.font = SET_FONT(14);
    
    _titleLabel = label;
    
    _titleLabel.text = titleString;
    
    return _titleLabel;

}

- (UILabel *)pickLabel
{
    if (_pickLabel) {
        
        return _pickLabel;
    }
    
    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(15 , 0,CGRectGetWidth(self.frame), 40)];
    label.text = @"合计：¥227.00 (含运费0.00)";
    
//    label.textColor = UIColorRGB(0x333333);
    
//    label.font = SET_FONT(16);
    
    _pickLabel = label;
    
    return _pickLabel;
    
 }

- (UILabel *)backLabel
{
    if (_backLabel) {
        
        return _backLabel;
    }
    
    UILabel * label  = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_titleLabel.frame), CGRectGetWidth(self.frame), 1)];
    
//    label.backgroundColor = UIColorRGB(0xd8d8d8);
    
    _backLabel = label;
    
    return _backLabel;
    

}
- (void)setStyle:(Style_maijia)style
{

    NSArray * array ;
    
    if (!self.backView) {
        
        return;
    }
    switch ( style) {
        case 0:
        {
            array = @[@"延长取货",@"联系顾客",@"确认发货"];
            
            [array enumerateObjectsUsingBlock:^(NSString * obj, NSUInteger idx, BOOL *stop) {
                
                UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
                [button setTitle:obj forState:UIControlStateNormal];
                
                button.frame = CGRectMake(140 + 80 * idx, 5, 75, 31);
                
//                button.titleLabel.font = SET_FONT(16);
                button.layer.cornerRadius = 5.0f;
                
//         /       [button setTitleColor:UIColorRGB(0x666666) forState:UIControlStateNormal];
                
//                [button setTitleColor:UIColorRGB(0x40a4c8) forState:UIControlStateSelected];
                
                [button addTarget:self action:@selector(bttonClicked:) forControlEvents:UIControlEventTouchUpInside];
                
                
                
                button.layer.borderColor = (__bridge CGColorRef _Nullable)([UIColor redColor]);
                
                [button.layer setBorderColor:(__bridge CGColorRef _Nullable)([UIColor redColor])];
                
                button.layer.borderWidth = 1.0f;
                
            
                [self.backView addSubview:button];
            }];
        
        }
            break;
        case 1:
        {
            array = @[@"删除订单",@"退货"];
            
            [array enumerateObjectsUsingBlock:^(NSString * obj, NSUInteger idx, BOOL *stop) {
                
                UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
                [button setTitle:obj forState:UIControlStateNormal];
                
                button.frame = CGRectMake(160 + 80 * idx, 5, 75, 31);
                
                button.titleLabel.font = SET_FONT(16);
                button.layer.cornerRadius = 5.0f;
                
//                [button setTitleColor:UIColorRGB(0x666666) forState:UIControlStateNormal];
                
//                [button setTitleColor:UIColorRGB(0x40a4c8) forState:UIControlStateSelected];
                
                [button addTarget:self action:@selector(bttonClicked:) forControlEvents:UIControlEventTouchUpInside];
                
            
                
//                button.layer.borderColor = UIColorRGB(0xd8d8d8).CGColor;
                
                button.layer.borderWidth = 1.0f;
                
                
                [self.backView addSubview:button];
            }];

        
        }
            break;
            
        case 2:
        {
        
            array = @[@"删除订单",@"评价"];
            
            [array enumerateObjectsUsingBlock:^(NSString * obj, NSUInteger idx, BOOL *stop) {
                
                UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
                [button setTitle:obj forState:UIControlStateNormal];
                
                button.frame = CGRectMake(160 + 80 * idx, 5, 75, 31);
                button.titleLabel.font = SET_FONT(16);
                button.layer.cornerRadius = 5.0f;
                
//                [button setTitleColor:UIColorRGB(0x666666) forState:UIControlStateNormal];
                
//                [button setTitleColor:UIColorRGB(0x40a4c8) forState:UIControlStateSelected];
                
                [button addTarget:self action:@selector(bttonClicked:) forControlEvents:UIControlEventTouchUpInside];
                
                
                
//                button.layer.borderColor = UIColorRGB(0xd8d8d8).CGColor;
                
                button.layer.borderWidth = 1.0f;
                
                
                [self.backView addSubview:button];
            }];

        
        }
            break;
            
        case 3:
        {
            array = @[@"取消订单",@"联系卖家"];
            
            [array enumerateObjectsUsingBlock:^(NSString * obj, NSUInteger idx, BOOL *stop) {
                
                UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
                [button setTitle:obj forState:UIControlStateNormal];
                
                button.frame = CGRectMake(160 + 80 * idx, 5, 75, 31);
                
                button.titleLabel.font = SET_FONT(16);
                button.layer.cornerRadius = 5.0f;
                
//                [button setTitleColor:UIColorRGB(0x666666) forState:UIControlStateNormal];
                
//                [button setTitleColor:UIColorRGB(0x40a4c8) forState:UIControlStateSelected];
                
                [button addTarget:self action:@selector(bttonClicked:) forControlEvents:UIControlEventTouchUpInside];
                
                
                
//                button.layer.borderColor = UIColorRGB(0xd8d8d8).CGColor;
                
                button.layer.borderWidth = 1.0f;
                
                
                [self.backView addSubview:button];
            }];

        
        }
            break;
            
        case 4:
        {
            array = @[@"查看物流",@"付款"];

            
            [array enumerateObjectsUsingBlock:^(NSString * obj, NSUInteger idx, BOOL *stop) {
                
                UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
                [button setTitle:obj forState:UIControlStateNormal];
                
                button.frame = CGRectMake(160 + 80 * idx, 5, 75, 31);
                
                button.titleLabel.font = SET_FONT(16);
                button.layer.cornerRadius = 5.0f;
                
//                [button setTitleColor:UIColorRGB(0x666666) forState:UIControlStateNormal];
                
//                [button setTitleColor:UIColorRGB(0x40a4c8) forState:UIControlStateSelected];
                
                [button addTarget:self action:@selector(bttonClicked:) forControlEvents:UIControlEventTouchUpInside];
                
                
                
//                button.layer.borderColor = UIColorRGB(0xd8d8d8).CGColor;
                
                button.layer.borderWidth = 1.0f;
                
                
                [self.backView addSubview:button];
            }];

        
        }
            
            break;
     
            case 5:
        {
        
            array = @[@"评价"];
            [array enumerateObjectsUsingBlock:^(NSString * obj, NSUInteger idx, BOOL *stop) {
                
                UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
                [button setTitle:obj forState:UIControlStateNormal];
                
                button.frame = CGRectMake(240 + 80 * idx, 5, 75, 31);
                
                button.titleLabel.font = SET_FONT(16);;
                button.layer.cornerRadius = 5.0f;
                
//                [button setTitleColor:UIColorRGB(0x666666) forState:UIControlStateNormal];
                
//                [button setTitleColor:UIColorRGB(0x40a4c8) forState:UIControlStateSelected];
                
                [button addTarget:self action:@selector(bttonClicked:) forControlEvents:UIControlEventTouchUpInside];
                
                
                
//                button.layer.borderColor = UIColorRGB(0xd8d8d8).CGColor;
                
                button.layer.borderWidth = 1.0f;
                
                
                [self.backView addSubview:button];
            }];

        
        }
            break;
            
            break;
            
        default:
            break;
    }


}

- (void)bttonClicked:(UIButton *)sender
{

    _selectButton.selected = NO;
    
//    _selectButton.layer.borderColor = [UIColorRGB(0xd8d8d8)CGColor];
    

        
        sender.selected = YES;
        
//        sender.layer.borderColor= [UIColor(0x40a4c8)CGColor];
        _selectButton = sender;
    
    

    
    if (self.selectButtonString) {
        
        self.selectButtonString(sender.titleLabel.text);
        

    }
    

    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
